package utils

import (
	"fmt"
	beeLogger "github.com/beego/bee/v2/logger"
	"github.com/beego/beego/v2/server/web"
)

var (
	RunMode   string //运行模式
	MYSQL_URL string //数据库连接
)

// 对象存储客户端
var (
	ObjectStorageClient string // 目前有oss minio，默认oss
)

// MinIo配置
var (
	MinIoBucketname       string
	MinIoEndpoint         string
	MinIoImghost          string
	MinIoUploadDir        string
	MinIoUpload_Audio_Dir string
	MinIoAccessKeyId      string
	MinIoAccessKeySecret  string
	MinIoUseSSL           string
	MinIoPort             string
	MinIoRegion           string
)

func init() {
	tmpRunMode, err := web.AppConfig.String("run_mode")
	if err != nil {
		panic("配置文件读取run_mode错误 " + err.Error())
	}
	RunMode = tmpRunMode
	fmt.Println("RunMode:", RunMode)

	config, err := web.AppConfig.GetSection(RunMode)
	if err != nil {
		panic("配置文件读取错误 " + err.Error())
	}
	beeLogger.Log.Info(RunMode + " 模式")
	MYSQL_URL = config["mysql_url"]

	if RunMode == "release" {

	} else {

	}

	// 对象存储客户端
	ObjectStorageClient = config["object_storage_client"]

	// MinIo相关
	{
		MinIoEndpoint = config["minio_endpoint"]
		MinIoBucketname = config["minio_bucket_name"]
		MinIoImghost = config["minio_img_host"]
		MinIoUploadDir = config["minio_upload_dir"]
		MinIoUpload_Audio_Dir = config["minio_upload_audio_dir"]
		MinIoAccessKeyId = config["minio_access_key_id"]
		MinIoAccessKeySecret = config["minio_access_key_secret"]
		MinIoUseSSL = config["minio_use_ssl"]
		MinIoPort = config["minio_port"]
		MinIoRegion = config["minio_region"]
	}
}
